﻿using OAS.Application.System.Dtos;
using OAS.Core;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace OAS.Application.RoleApp.Services
{
    public class RoleService : Repository<Role>, IRoleService, ITransient
    {
        public async Task<List<Role>> GetAllRole()
        {
            return await base.GetListAsync();
        }
        public async Task<object> GetRoleList(DtoQuery dto)
        {
            RefAsync<int> total = 0;
            var list = await base.AsQueryable().Where(o => o.RoleName.Contains(dto.KeyWord??"")).ToPageListAsync(dto.PageIndex, dto.PageSize, total);
            return new { list, total };
        }
        public async Task AddRole(Role role)
        {
            if (base.AsQueryable().Any(o => o.RoleName == role.RoleName)) throw Oops.Oh("该角色已存在");
            await base.InsertAsync(role);
        }
        public async Task UpdateRole(Role role)
        {
            if (base.AsQueryable().Any(o => o.Role_Id != role.Role_Id && o.RoleName == role.RoleName)) throw Oops.Oh("该角色已存在");
            await base.UpdateAsync(role);
        }
        public async Task DeleteRole(string[] ids)
        {
            await base.DeleteByIdsAsync(ids);
        }
    }
}
